package march.finalmarch22.march02;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class Driver02 {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Job job = Job.getInstance(new Configuration());

        job.setJarByClass(Driver02.class);

        job.setMapperClass(Mapper02.class);
        job.setReducerClass(Reducer02.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Text.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        job.setOutputFormatClass(StuOutputFormat.class);

        Path outPath = new Path("F:\\test00\\output02");
        FileSystem fileSystem = outPath.getFileSystem(job.getConfiguration());

        if(fileSystem.exists(outPath)){
            fileSystem.delete(outPath,true);
        }
        FileInputFormat.setInputPaths(job,new Path("F:\\test00\\input01"));
        FileOutputFormat.setOutputPath(job,outPath);
        boolean b = job.waitForCompletion(true);
        System.exit(b?0:1);
    }
}
